<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
</head>

<body>
	<!DOCTYPE html
		PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<title>DataGrid 数据表格</title>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<link href="../../demo/demo.css" rel="stylesheet" type="text/css" />

		<script src="../../scripts/boot.js" type="text/javascript"></script>
		<style type="text/css">
			html,
			body {
				margin: 0;
				padding: 0;
				border: 0;
				width: 100%;
				height: 100%;
				overflow: hidden;
			}

			.sx {
				color: red;
			}
		</style>
	</head>

	<body>
		<h1>借阅信息列表</h1>

		<div style="width: 100%;">
			<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
				<table style="width: 100%;">
					<tr>
						<td style="width: 100%;"><a class="mini-button" iconCls="icon-add" onclick="add()">新增借阅</a></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="mini-fit">
			<div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" allowResize="true"
				url="../../borrowinfolistaction?method=showborrinfolist" idField="id" multiSelect="true">
				<div property="columns">

					<div type="checkcolumn"></div>
					<div type="indexcolumn">序号</div>
					<div field="borrowid" width="120" headerAlign="center" allowSort="true">借阅编号</div>
					<div field="bookname" id="bookid" name="bookid" width="120" headerAlign="center" allowSort="true"
						renderer="">图书名称</div>
					<div field="borrower" width="120" headerAlign="center" allowSort="true">借阅人</div>
					<div field="phone" width="120" headerAlign="center" allowSort="true">联系电话</div>
					<div field="borrowtime" width="120" headerAlign="center" allowSort="true" renderer=""
						dateFormat="yyyy-MM-dd HH:mm:ss">借阅时间</div>
					<div field="returntime" id="returntime" name="returntime" width="120" headerAlign="center"
						allowSort="true" renderer="" dateFormat="yyyy-MM-dd HH:mm:ss">归还日期</div>
					<div name="Operate" width="120" headerAlign="center" allowSort="true" renderer="onActionRenderer">
						操作按钮</div>
				</div>
			</div>
		</div>


		<script type="text/javascript">
			mini.parse();
			var grid = mini.get("datagrid1");
			grid.load();
			grid.sortBy("borrowtime", "desc");
			var bookname;
			//新增页面
			function add() {
				mini.open({
					url: bootPATH + "../pages/borrowinfo/borrowinfoadd.html",
					title: "新增借阅信息",
					width: 600,
					height: 400,
					ondestroy: function (action) {
						grid.reload();
					}
				});
			}

			//操作按钮渲染
			function onActionRenderer(e) {
				var record = e.record;

				if (record.returntime < new Date()) {
					return '&nbsp;&nbsp;&nbsp;&nbsp;<a class="mini-button" iconCls="icon-edit" onclick="deleteBorrowInfo(\'' + record.borrowid + '\')">删除</a>'

				} else {
					return '&nbsp;&nbsp;&nbsp;&nbsp;<a class="mini-button" iconCls="icon-edit" onclick="returnBook(\'' + record.borrowid + "\' , \'" + record.bookid + '\')">还书</a>'
				}

			}
			//还书  borrowid:"Borrow20220011"
			function returnBook(borrowid, bookid) {
				$.ajax({
					url: "../../borrowinfolistaction?method=returnbook&borrowid=" + borrowid + "&bookid=" + bookid,
					type: 'post',
					cache: false,
					success: function (text) {
						var o = mini.decode(text)
						mini.confirm(o.msg, "还书信息", function (action) {
							grid.reload();
							CloseWindow("save");
						});
					},
					error: function (jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
						CloseWindow();
					}
				});
			}

			//删除
			function deleteBorrowInfo(borrowid) {
				$.ajax({
					url: "../../borrowinfolistaction?method=deleteborrowinfo&borrowid="
						+ borrowid,
					type: 'post',
					cache: false,
					success: function (text) {
						var o = mini.decode(text);
						console.log(o);
						mini.confirm(o.msg, "删除信息", function (action) {
							grid.reload();
							CloseWindow("save");
						});
					},
					error: function (jqXHR, textStatus, errorThrown) {
						alert(jqXHR.responseText);
						CloseWindow();
					}
				});
			}

			function CloseWindow(action) {
				if (window.CloseOwnerWindow) {
					return window.CloseOwnerWindow(action);
				} else {
					window.close();
				}
			}
		</script>

	</body>


	</html>